{% extends "member/layout.html" %}

{% block content %}
<div class="card shadow-sm">
    <div class="card-header bg-primary text-white">
        <h5 class="mb-0">创建新项目</h5>
    </div>
    <div class="card-body">
        <form method="post">
            <input name="csrf_token" type="hidden" value="{{ csrf_token() }}">
            {{ form.csrf_token }}

            <div class="alert alert-info">
                <i class="bi bi-info-circle"></i> 新项目将自动设置为"草稿"状态，创建后可提交审核
            </div>

            <div class="row mb-3">
                <div class="col-md-6">
                    <label for="name" class="form-label">项目名称</label>
                    <input type="text" class="form-control" id="name" name="name" required>
                </div>
                <div class="col-md-6">
                    <label for="category_id" class="form-label">项目类别</label>
                    <select class="form-select" id="category_id" name="category_id" required>
                        <option value="">-- 选择类别 --</option>
                        {% for category in categories %}
                        <option value="{{ category.id }}">{{ category.name }}</option>
                        {% endfor %}
                    </select>
                </div>
            </div>

            <div class="row mb-3">
                <div class="col-md-6">
                    <label for="level_id" class="form-label">项目级别</label>
                    <select class="form-select" id="level_id" name="level_id" required>
                        <option value="">-- 选择级别 --</option>
                        {% for level in levels %}
                        <option value="{{ level.id }}" style="color: {{ level.color }};">
                            {{ level.name }} (优先级: {{ level.priority }})
                        </option>
                        {% endfor %}
                    </select>
                </div>
                <div class="col-md-6">
                    <label for="approval_flow_id" class="form-label">审批流程</label>
                    <select class="form-select" id="approval_flow_id" name="approval_flow_id" required>
                        <option value="">-- 选择流程 --</option>
                        {% for flow in flows %}
                        <option value="{{ flow.id }}">
                            {{ flow.name }} ({{ flow.department.name if flow.department else '通用' }})
                        </option>
                        {% endfor %}
                    </select>
                </div>
            </div>

            <div class="row mb-3">
                <div class="col-md-6">
                    <label for="first_approver_id" class="form-label">第一审批人</label>
                    <select class="form-select" id="first_approver_id" name="first_approver_id" required>
                        <option value="">-- 选择审批人 --</option>
                        {% for approver in approvers %}
                        <option value="{{ approver.id }}">
                            {{ approver.name }} ({{ approver.department.name }})
                        </option>
                        {% endfor %}
                    </select>
                </div>
                <div class="col-md-6">
                    <label for="start_date" class="form-label">开始日期</label>
                    <input type="date" class="form-control" id="start_date" name="start_date" required>
                </div>
            </div>

            <div class="row mb-3">
                <div class="col-md-6">
                    <label for="end_date" class="form-label">结束日期</label>
                    <input type="date" class="form-control" id="end_date" name="end_date" required>
                </div>
            </div>

            <div class="mb-3">
                <label for="description" class="form-label">项目描述</label>
                <textarea class="form-control" id="description" name="description" rows="3"></textarea>
            </div>

            <div class="mb-4">
                <label class="form-label">项目成员</label>
                <div class="row">
                    {% for member in members %}
                    <div class="col-md-4 mb-2">
                        <div class="form-check">
                            <input class="form-check-input" type="checkbox"
                                   name="member_ids" value="{{ member.id }}"
                                   id="member{{ member.id }}">
                            <label class="form-check-label" for="member{{ member.id }}">
                                {{ member.name }} ({{ member.department.name }})
                            </label>
                        </div>
                    </div>
                    {% endfor %}
                </div>
            </div>

            <div class="d-flex justify-content-between">
                <div>
                    <button type="submit" class="btn btn-primary">
                        <i class="bi bi-save"></i> 创建项目
                    </button>
                    <a href="{{ url_for('member.jira.list_projects') }}" class="btn btn-secondary">
                        <i class="bi bi-x-circle"></i> 取消
                    </a>
                </div>
            </div>
        </form>
    </div>
</div>
{% endblock %}